package com.meituan.catering.management.product.biz.model.converter;

import com.meituan.catering.management.common.model.biz.AuditingBO;
import com.meituan.catering.management.product.biz.model.ProductBO;
import com.meituan.catering.management.product.dao.model.ProductDO;

import java.util.Objects;

/**
 * 从其他数据模型向商品BO的转换器
 */
public abstract class ProductBOConverter {
    public static ProductBO toProductBO(ProductDO productDO) {
        if (Objects.isNull(productDO)) {
            return null;
        }
        ProductBO productBO = new ProductBO();
        productBO.setName(productDO.getName());
        productBO.setUnitPrice(productDO.getUnitPrice());
        productBO.setUnitOfMeasure(productDO.getUnitOfMeasure());
        productBO.setMinSalesQuantity(productDO.getMinSalesQuantity());
        productBO.setIncreaseSalesQuantity(productDO.getIncreaseSalesQuantity());
        productBO.setDescription(productDO.getDescription());
        productBO.setEnabled(productDO.getEnabled());
        productBO.setId(productDO.getId());
        productBO.setTenantId(productDO.getTenantId());
        productBO.setVersion(productDO.getVersion());
        productBO.setAuditing(toAuditingBO(productDO));
        return productBO;
    }

    public static AuditingBO toAuditingBO(ProductDO productDO) {
        if (Objects.isNull(productDO)) {
            return null;
        }
        AuditingBO auditingBO = new AuditingBO();
        auditingBO.setCreatedBy(productDO.getCreatedBy());
        auditingBO.setCreatedAt(productDO.getCreatedAt());
        auditingBO.setLastModifiedBy(productDO.getLastModifiedBy());
        auditingBO.setLastModifiedAt(productDO.getLastModifiedAt());
        return auditingBO;
    }
}
